#include "menu.h"
#include "ui_menu.h"
#include "Sound/soundmanager.h"
#include "gamemanager.h"
Menu::Menu(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Menu)
{
    ui->setupUi(this);
    Init();
}

Menu::~Menu()
{
    delete ui;
}

void Menu::Init()
{
    QMap<QString,MyButton*> btns =
    {
        {"返回游戏",ui->BackBtn},
        {"返回主页",ui->homeBtn},
        {"菜单-查看图鉴",ui->AlbumBtn},
        {"菜单-查看数值",ui->DataBtn},
        {"菜单-语音",ui->soundBtn},
        {"菜单-音乐",ui->bgmBtn},
        {"菜单-音效",ui->bgseBtn}
    };

    for(auto i = btns.begin();i != btns.end();i++)
    {
        i.value()->SetSelectedDisabled(true);
        if(UILib::Instance().btns.contains(i.key()) && UILib::Instance().btns[i.key()])
        {
            i.value()->info = UILib::Instance().btns[i.key()];
            i.value()->Refresh(i.value()->info);
        }
    }
    //调整音量
    connect(ui->soundSlider,&QSlider::valueChanged,[=](int value){
        SoundManager::Instance().SetVolume(value,SoundManager::Instance().SOUND);
        GameManager::Instance().soundVolume = value;
        GameManager::Instance().Save();
    });
    connect(ui->bgmSlider,&QSlider::valueChanged,[=](int value){
        SoundManager::Instance().SetVolume(value,SoundManager::Instance().BGM);
        GameManager::Instance().bgmVolume = value;
        GameManager::Instance().Save();
    });
    connect(ui->bgseSlider,&QSlider::valueChanged,[=](int value){
        SoundManager::Instance().SetVolume(value,SoundManager::Instance().BGSE);
        GameManager::Instance().bgseVolume = value;
        GameManager::Instance().Save();
    });
    ui->soundSlider->setValue(GameManager::Instance().soundVolume);
    ui->bgmSlider->setValue(GameManager::Instance().bgmVolume);
    ui->bgseSlider->setValue(GameManager::Instance().bgseVolume);
}
